import { Pipe, PipeTransform } from '@angular/core';
//用于数组转换成str的过滤器
@Pipe({
  name: 'arrayToStr'
})
export class arrayToStrPipe implements PipeTransform {

  //keyName = 数组的key ， splitStr = 分割符号
  transform(value: any, keyName?: any, splitStr?: string): any {
    let result : string = '';
    if(typeof(splitStr) == 'undefined'){
        splitStr = ',';
    }
    if(value) {
          for(let item of value){
              if(item.hasOwnProperty(keyName)){
                  result += item[keyName] + splitStr;
              }
          }
          if(result != ''){
              result = result.substring(0,result.length - 1);
          }
    }
    return result;
  }

}
